#include "head.h"

int enqueue(int net_fd, queue_t *pqueue)
{
    node_t *pnew_node = (node_t *)calloc(1, sizeof(node_t));


    pnew_node->net_fd = net_fd;

    if(pqueue->queue_size == 0)
    {
        pqueue->head = pnew_node;
        pqueue->tail = pnew_node;

    }
    else
    {

        pqueue->tail->pnext = pnew_node;
        pqueue->tail = pnew_node;
    }
    pqueue->queue_size++;
    return 0;
}

int dequeue(queue_t *pqueue)
{
    if(pqueue->queue_size == 0)
    {
        printf("队列为空，不可出队\n");
        return -1;
    }

    node_t *tmp = pqueue->head;
    int net_fd = tmp->net_fd;
    pqueue->head = tmp->pnext;
    
    if(pqueue->queue_size == 1)
    {
        pqueue->tail = NULL;
    }

    pqueue->queue_size--;
    free(tmp);
    return net_fd;
}

